﻿@page "/Bas/CodingRule/Edit"
@using nERP.ViewModel.Bas.CodingRuleVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
            <Select @bind-Value="@Model.Entity.CodingListId" Items="AllCodingLists" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <BootstrapInput @bind-Value="@Model.Entity.Seq" />
            <Select @bind-Value="@Model.Entity.CodeRule" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <BootstrapInput @bind-Value="@Model.Entity.FixedValue" />
            <Select @bind-Value="@Model.Entity.FixedRule" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]" />
            <BootstrapInput @bind-Value="@Model.Entity.GlideLen" />
            <BootstrapInput @bind-Value="@Model.Entity.StartNumber" />
            <BootstrapInput @bind-Value="@Model.Entity.GlideStep" />
            <BootstrapInput @bind-Value="@Model.Entity.Glide" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button ButtonType="ButtonType.Submit" IsAsync="true" Text="@WtmBlazor.Localizer["Sys.Submit"]" Icon="fas fa-check" Color="Color.Success" />
            <Button OnClick="OnClose" Icon="fas fa-arrow-right-from-bracket" Text="@WtmBlazor.Localizer["Sys.Close"]" Color="Color.Info" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private CodingRuleVM Model = new CodingRuleVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/Bas/CodingRule/Edit", (s) => "Sys.OprationSuccess", method: HttpMethodEnum.PUT);
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllCodingLists = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllCodingLists = await WtmBlazor.Api.CallItemsApi("/api/Bas/CodingRule/GetCodingLists");
        AllCodingLists.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<CodingRuleVM>($"/api/Bas/CodingRule/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
